/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DBTables;

import DBManager.*;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.SQLException;

/**
 *Класс таблицы User
 * @author Ivan
 */
public class TUser extends DataManager {

    public String Login;
    public String Password;
    public String E_Mail;
    public String Interests;

    public TUser(Connection conn, String tableName) throws SQLException {
        super(conn, tableName);

        SelectPrepStatement = connection.prepareStatement("select * from " + TableName);
        InsertPrepStatement = connection.prepareStatement("insert into " + TableName + "(Login,Password,E_Mail,Interests) values (?,?,?,?) ");
        UpdatePrepStatement = connection.prepareStatement("update " + TableName + " set Login = ?,Password = ?,E_Mail = ?,Interests = ? Where Id_User = ?");
        DeletePrepStatement = connection.prepareStatement("delete from " + TableName + " where Id_User = ?");
    }

    @Override
    public void SetValues(PreparedStatement prepareStatement) throws SQLException {

        ParameterMetaData metaData = prepareStatement.getParameterMetaData();
        int countParameters = metaData.getParameterCount();

        if (countParameters >= 4) // for insert prepared statement
        {
            prepareStatement.setString(1, Login);
            prepareStatement.setString(2, Password);
            prepareStatement.setString(3, E_Mail);
            prepareStatement.setString(4, Interests);
        }

        if ((countParameters == 5))// for update prepared statement
        {
            prepareStatement.setString(5, ID_Table);
        }

        if ((countParameters == 1))// for delete prepared statement
        {
            prepareStatement.setString(1, ID_Table);
        }
    }
}
